#include <iostream>
#include <queue>

using namespace std;

const int N = 300;
int n;
int l[N], r[N];

void bfs()
{
    queue<int> q;
    q.push(1);

    while(q.size())
    {
        auto p = q.front(); q.pop();
        cout << p << " ";

        if(l[p]) q.push(l[p]);
        if(r[p]) q.push(r[p]);
    }
    cout << endl;
}
int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> l[i] >> r[i];
    }
    bfs();
    return 0;
}